<?php
/**
 *
 * @package    opensocial
 * @subpackage datarequest
 * @author     Daniel Botelho <botelho.daniel@gmail.com>
 */
class OSFetchActivitiesRequest implements OSDataRequestable
{
  const NEWFETCH_ACTIVITIES_REQUEST_PATTERN = 'newFetchActivitiesRequest(%s)';
  
  private $idSpec;
  
  public function __construct($idSpec)
  {
  	if( !($idSpec instanceof OSFriends || $idSpec instanceof OSPerson) )
  	  throw new Exception("$idSpec is not valid!");
    $this->idSpec = $idSpec;
  }
  
  public function getActivitiesStreamVarName()
  {
  	return $this->getOptionalKey()."['activities']";
  }
  
  public function getIdSpec(){ return $this->idSpec; }
  
  public function generateDataRequest(OSDataRequest $dataRequest)
  {
  	//vai buscar o nome da variável que é usada para o dataRequest
    $request_var = $dataRequest->getDataRequestVarName();

    $html .= $request_var.".add(".$request_var.".".sprintf(OSFetchActivitiesRequest::NEWFETCH_ACTIVITIES_REQUEST_PATTERN,$this->getIdSpec()->getType()).",\"".$this->getOptionalKey()."\");\n";
  	return $html;
  }
  
  /**
   * 
   */
  public function getOptionalKey()
  {
  	return $this->idSpec->getVarName()."_Activities";
  }
}